{extend name="base"/}
{block name="main"}
<style>.form_message {display: block; height: 38px; line-height: 38px; text-align: left;color:#999;}
.formControls .btn {float:left;margin-right:15px;}
.clear{clear:both;}
.form-label {font-weight: bold;}</style>
<article class="cl pd-20">
    <div id="tab_demo" class="HuiTab" style="margin-bottom: 15px; position:relative;">
        <div class="tabBar clearfix">
            <span class="current">站点配置</span>
        </div>
    </div>
    <form id="main_form" method="post">
        <div class="form form-horizontal" id="main">
            <input name="a" value="0" type="hidden">
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>使用方法：</label>
                <div class="formControls col-xs-8 col-sm-9" style="width: 50%;line-height: 2.0;">

                        <div style="display: flex;flex-direction: column; margin-left: 10px;">
                            <span>1.默认未开启,点击开启按钮启用</span>
                            <span>2.后续会自动检测是否有新版本,发现新版本,点击升级,升级到最新版</span>
                            <span>3.点击访问链接查看</span>
                        </div>

                </div>
            </div>


            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>访问链接：</label>
                <div class="formControls col-xs-8 col-sm-9" style="line-height: 26px;">
                    {if $packaged}
                    <a href="{$link}" target="_blank">{$link}</a>
                    {else}
                    请先启用,启用后才会显示
                    {/if}
                </div>
            </div>


            <div class="row cl">
                <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                    {if !$packaged}
                        <input class="btn btn-primary radius" onclick="install(0)" type="button" value="   启用   " style="padding:6px 12px;">
                    {else}
                        {if $last.version > $now.version}
                        <input class="btn btn-primary radius" onclick="install(1)" type="button" value="   升级   " style="padding:6px 12px;">
                        {/if}
                    {/if}
                </div>
            </div>

        </div>
    </form>
</article>
{/block}
{block name="script"}
<script type="text/javascript">

    $("#main_form").on('submit',function () {
        return false;
    });

    var flag = false;
    function install(type) {

        if(flag)return;
        flag = true;

        var msg = type === 0 ? "正在启用,请稍候!" : "正在升级,请稍候!";
        var res_msg = type === 0 ? "启用" : "升级";
        layer.msg(msg, {
            icon: 16
            ,shade: 0.05
            ,time:900000
        });

        $.ajax({
            url: "{:url('h5/install')}",
            type: 'POST',
            cache: false,
            data: new FormData($('#main_form')[0]),
            processData: false,
            contentType: false,
            dataType: 'json',
            success:function (res) {
                if (res["code"] > 0) {
                    layer.msg(res_msg+'成功!',{icon:1,time:1000},function () {
                        window.location.reload();
                    });
                }else{
                    layer.msg(res['message'],{icon:5,time:1000});
                    flag = false;
                }
            },
            fail:function (err) {
                layer.msg(res_msg+"失败",{icon:5,time:1000});
                flag = false;
            }
        });
    }
</script>
{/block}